package com.wkck.controller.frontend;

import com.wkck.VO.FrontendDataVo;
import com.wkck.VO.PageResult;
import com.wkck.domain.Notice;
import com.wkck.domain.NoticeContent;
import com.wkck.dto.GetAllNoticesDto;
import com.wkck.result.Result;
import com.wkck.service.HomeFrontendService;
import com.wkck.utils.DateTimeGeneration;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: CK
 * @Date: 2024/02/17/22:30
 * @Description:
 */
@Api(value = "首页Api", tags = "首页Api")
@Slf4j
@RestController
@RequestMapping("/user/frontend")
public class HomeFrontendController {

    @Autowired
    private HomeFrontendService homeFrontendService;

    /***
    * @Author: CK
    * @Date: 2024/2/23
    * @Description: 得到首页数据
    */
    @GetMapping
    @ApiOperation(value = "首页推荐数据")
    public Result<FrontendDataVo> getHomeFrontendListInfo() {
        log.info("获取首页推荐数据时间 ===============> {}", DateTimeGeneration.now());
        return Result.success(homeFrontendService.getFrontendData());
    }

    /***
     * @Author: CK
     * @Date: 2024/3/23
     * @Param: [id]
     * @Description: 预览新闻
     */
    @GetMapping("/preview-content/{id}")
    @ApiOperation(value = "预览公告或通知")
    public Result<NoticeContent> getPreviewNewsContent(@PathVariable Long id) {
        log.info("预览公告或通知id ===> {}", id);
        return Result.success(homeFrontendService.getPreviewNoticeContent(id));
    }

    /***
    * @Author: CK
    * @Date: 2024/3/27
    * @Param: [type]
    * @return: @Description: 得到所有通知
    */
    @PostMapping("/get-notices")
    @ApiOperation(value = "得到所有通知")
    public Result<PageResult> getAllNotice(@RequestBody GetAllNoticesDto dto) {
        log.info("得到所有通知或公告 ===> {}", dto);
        return Result.success(homeFrontendService.getAllNotice(dto));
    }
}
